package com.android.functionmanagement.util;

import com.uwatch.helowin.R;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class ToastUtil {
	private static Toast mToast;
	private static Handler mHandler = new Handler();
	
	private static Runnable runnable = new Runnable() {
		public void run() {
			mToast.cancel();
			mToast = null;
		}
	};

	public static void showShortToast(Context context, String message) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.layout_custom_toast, null);
		TextView text = (TextView) view.findViewById(R.id.toast_message);
		text.setText(message);
		mHandler.removeCallbacks(runnable);
		if (mToast == null) {
			mToast = new Toast(context);
			mToast.setDuration(Toast.LENGTH_SHORT);
			mToast.setGravity(Gravity.BOTTOM, 0, 10);
			mToast.setView(view);
		}
		mHandler.postDelayed(runnable, 1500);
		mToast.show();
	}
}